|
|
 |
|
|
|
|
Private Type TEXTMETRIC
tmHeight As Long
tmAscent As Long
tmDescent As Long
tmInternalLeading As Long
tmExternalLeading As Long
tmAveCharWidth As Long
tmMaxCharWidth As Long
tmWeight As Long
tmOverhang As Long
tmDigitizedAspectX As Long
tmDigitizedAspectY As Long
tmFirstChar As Byte
tmLastChar As Byte
tmDefaultChar As Byte
tmBreakChar As Byte
tmItalic As Byte
tmUnderlined As Byte
tmStruckOut As Byte
tmPitchAndFamily As Byte
tmCharSet As Byte
End Type
Private Declare Function GetTextMetrics Lib "gdi32"
Alias "GetTextMetricsA" (ByVal hdc As Long, _
lpMetrics As TEXTMETRIC) As Long |
|
|
|
|
|
|
|
|
Example program FMetrics, shown in Figure 4.4, uses GetTextMetrics to learn about a font's internal leading, ascent, descent, and height values. It draws some text with these values displayed graphically. |
|
|
|
|
|
|
|
|
Once you know how to use the GetTextMetrics function, you can modify the Styles program described earlier so that it displays text in different fonts aligned on their baselines. Example program Styles2, shown in Figure 4.5, uses this method to display text using randomly selected fonts. |
|
|
|
|
|
|
|
|
The main difference between programs Styles and Styles2 comes just before the program prints text. Program Styles2 adjusts the text's Y coordinate using the current font's ascent. The value y + max_size gives the Y coordinate where the font's base should be. Subtracting the font's ascent value places font's baseline at this Y coordinate. |
|
|
|
 |
|
|
|
|
' Get the font's metrics. GetTextMetrics hdc, text_metrics
ascent = ScaleY(text_metrics.tmAscent, vbPixels, ScaleMode)
' Display the text. CurrentY = y + max_size - ascent
Print new_word; " "; |
|
|
|
|
|